Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Partial Class TheatreStaff_SalesReports
	Inherits System.Web.UI.Page

	Protected Sub Page_Load(sender As Object, e As EventArgs)
		'srcgrdSession.SelectParameters["username"].DefaultValue = Page.User.Identity.Name;
		'srcgrdSchedule.SelectParameters["username"].DefaultValue = Page.User.Identity.Name;
		'grdSpecialTickets.Sort("MovieTitle", SortDirection.Ascending);

		Dim connectionString As String
		connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

		Dim con As New SqlConnection(connectionString)
		Dim con1 As New SqlConnection(connectionString)
		Dim cmd As New SqlCommand("SELECT TheatreId from TheatreStaff WHERE TheatreStaffUsername=@username", con)
		cmd.Parameters.AddWithValue("@username", Page.User.Identity.Name)

		Using con
			con.Open()
			Dim TheatreID As Object = cmd.ExecuteScalar()
			If TheatreID IsNot Nothing Then
				lblId.Text = TheatreID.ToString()
			End If
		End Using
		'SqlCommand cmd1 = new SqlCommand("SELECT Movie.MovieTitle,Movie.MovieId FROM Movie WHERE Movie.TheatreId=@TheatreId", con1);
		'cmd1.Parameters.AddWithValue("@TheatreId", lblId.Text);

		'using (con1)
		'{
		'    con1.Open();
		'    SqlDataReader Reader = cmd1.ExecuteReader();

		'    if (Reader.HasRows)
		'    { 
		'        while (Reader.Read())
		'        {

		'        }
		'    }

		srcMovie.FilterExpression = "title LIKE '%{0}%' OR sessiondate= '{1}'"
		'srcMovie.FilterExpression = "title LIKE '%{0}%'";


		'}
		Dim con3 As New SqlConnection(connectionString)
		Dim cmd2 As New SqlCommand("SELECT TheatreId from TheatreStaff WHERE TheatreStaffUsername=@username", con3)

		cmd2.Parameters.AddWithValue("@username", Page.User.Identity.Name)

		Using con3
			con3.Open()
			Dim TheatreID As Object = cmd2.ExecuteScalar()
			If TheatreID IsNot Nothing Then
				lblId.Text = TheatreID.ToString()
			End If
		End Using
		Dim con4 As New SqlConnection(connectionString)
		Dim cmd3 As New SqlCommand("SELECT Theatrename from Theatre WHERE Theatreid=@theatreid", con4)

		cmd3.Parameters.AddWithValue("@theatreid", lblId.Text)


		Using con4
			con4.Open()
			Dim Theatrename As Object = cmd3.ExecuteScalar()

			If Theatrename IsNot Nothing Then

				Label4.Text = Theatrename.ToString()
			End If
		End Using

	End Sub


    Protected Sub CreateReport(ByVal sender As Object, ByVal e As EventArgs)
        If txtTitle.Text = "" AndAlso txtDate.Text = "" Then
            'srcMovie.FilterExpression = "title LIKE 'Caroline' OR sessiondate like '10'";

            srcMovie.FilterExpression = "title LIKE '%{0}%' OR sessiondate= '{1}'"
        ElseIf txtTitle.Text <> "" AndAlso txtDate.Text <> "" Then

            srcMovie.FilterExpression = "title LIKE '%{0}%' AND sessiondate= '{1}'"
        Else

            If txtDate.Text = "" Then

                srcMovie.FilterExpression = "title = '{0}'"
            Else
                If txtTitle.Text = "" Then
                    srcMovie.FilterExpression = "sessiondate = '{1}'"
                End If
            End If
        End If

    End Sub
End Class
